home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Scene 96
/
Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso
/
misc
/
coding
/
dos32xtn
/
docs.doc
< prev
next >
Wrap
Text File
|
1996-09-21
|
22KB
|
522 lines
DOS32 EXTENTION PACKAGE FOR DJGPP
Version 1.00
release date 21.9.1996
by rasputin aka Christian Lageman
Contents
--------
I. Legal stuff
II. How-to-use and how-it-works
III. Memory model & technical stuff
IV. Removed and changed library functions
V. New functions & API
VI. New command line options
VII. How to compile the sources
VIII.Known bugs and problems
IX. Contact the author and get the original GNU stuff
X. Credits & greets
I. Legal stuff
---------------
1. This package is distributed under the GNU General Public License and the
GNU Library General Public License of the Free Software Foundation.
(These licenses are in the files "copying" and "copying.lib")
2. There is no warranty that any part of this package works or works the way
it is meant to be.
3. The author isn't responsible for any damage caused by the use of this
package.
4. Parts of this package have an different author than the author of this
package - they are distributed under the terms of their original authors
distribution license.
YOU MAY NOT MODIFY AND/OR REMOVE ANY COPYRIGHT NOTICES.
5. The DOS32 package by Adam Seychell IS NOT PART OF THIS PACKAGE AND IT'S
LICENSE. It is distributed with this package only for legal reasons.
Some parts of this package are copyrighted by the following persons/institutions:
DJ Delorie
Adam Seychell
CW Sandmann
Eli Zaretskii
Regents of the University of California
Oleg Pliss
Free Software Foundation
all other people whose copyright notice you find in any file included in this
package
II. How-to-use and how-it-works
-------------------------------
First install the libs (run me_1st!.exe to obtain infos about it).
In the new dir LIBDOS32 you will find the library for DOS32, in the dir
INCDOS32 the header files.
To invoke the DOS32 executable output, just start the batch swap.bat in the
DJGPP base dir. It exchanges the original environment file with a new one,
which contains different directories for the standard include and library files,
so that the DOS32 libs and headers are used. This also changes the standard gcc
output to DOS32 executables, because gcc searches for the "specs" file in the
standard library dir, so automatically a new specs file (which causes DOS32
output) is used.
If you want to link several object files to an executable you can use the
dos32.lnk linker script in LIBDOS32 or the linker emulation i386dos32. The
emulation, however, WON'T work when you link the standard DOS32 lib and crt0.o
together with the object files - the startup code depends on the
djgpp_first_ctor etc. symbols which are not created by the emulation (this was
too library specific to add to the emulation). In this case you will have to
use the linker script.
After linking the DOS32 executables don't have a stubloader. You'll have to call
stubify to fix this. Gcc does this automatically. (Ok. One could convince the
linker to do this, but in this case one would also have to edit most makefiles
for gcc and my main aim was to minimize such changes.)
If you want to produce a DOS32 dll, you'll have to compile the involved source
files to objects. Then link them with the emulation i386dos32dll together. The
output will be a plain DOS32 dll, which can be loaded via __dos32_load_dll.
(No more dxegen. <g>)
But always remember:
- DOS32 DLLs don't know anything about the main program.
- So, they can't use any variables or functions of the main program
directly.
- The __dos32_load_dll tries to zero out the region of memory, where
the DLL is loaded. But I'm not sure if DOS32 doesn't mess this up.
So, don't count on any bss var to contain zero.
- Avoid to use the standard libraries in the DLL. Many of them depend on
startup variables or drag in a lot of other functions.
- I haven't tested the dll option very extensively, it might be buggy.
(And, what makes it worse, the dll output is a quite dirty hack, what
makes bugs more likely.)
So, the main use of dlls would be hardware drivers (p.e. video, sound) and
similar stuff.
If you want to create go32-coffs files again, just call swap.bat - it will
switch back to go32 output (and libs).
III. Memory model & technical stuff
-----------------------------------
Ok. I suppose you know the memory model of dos32. If not please read the dos32
docs FIRST, otherwise you won't understand anything. (And I'm NOT going to
explain the basic memory model of dos32.)
The main problem of DOS32 is, that it has a not very good normal memory
allocation method (compared to other extenders). You can request memory only
64 times - this makes it unusable for malloc & co. So we must alloc all we need
upon the start. This library has possible two ways to do this: a) you can
specify the amount of memory which must remain free for other applications
(default mode, with free memory zero) or b) you can specify the amount which
your application allocates. DOS32 also provides a very nice function to alloc
DMA buffers. However these functions will fail when called during run time and
the application has already grapped all memory. So, I've included the feature
that a certain number of DMA buffers can be alloced upon the start before any
other memory is requested. (I strongly recommend to use always this method, even
if there is enough memory for an DMA buffer - the free mem might be too bad
located for an DMA buffer, crossing 64k boundaries or being shattered through
the whole RAM.)
The second, minor problem of DOS32 is that it's error output when an exception
occurs is very bad. No registers, no exception address. By default the library
uses it's own exception handlers, which dump out all infomation you need. DOS32,
however, doesn't provide any exception handler functions or virtualizes the PIC,
so that the lower IRQs and the exceptions 8-15 use the same interrupts. This
forces an IRQ check in the exceptions handlers. The consequence is an additional
slowdown (especially for handler 8), because my check method uses 5 port
instructions (if you have a faster method -> mail me). You can switch off
the exception handling for IRQ 8 or all IRQs by setting the corresponding crt0
flags. An alternative is to link with noexcept.o, which has no exception
handlers and therefore is about 1 kB smaller.
IV. Removed and changed library functions
------------------------------------------
I had to remove some of the original library function, because they won't work
under DOS32 or are obsolete. Programs which use these function must be updated.
There are not so many important changed and removed functions, because I wanted
to reduce the changes to a minimum. Most programs should run without or with
only minimum changes.
Removed:
brk & sbrk - our memory model has no "break" which can be moved, so I removed
them, although they could be easyly faked via __mem_top & __mem_max
(see malloc.c how to do this)
all dmpi functions - killed, DOS32 is no DPMI host, so we can't call any
functions (although it has some similar functions)
all go32 functions - killed, what extender are we using, he ?
intdos functions - different behavior, they contain a normal protected mode DOS
int call, NOT an switch to realmode; the original
"translated" functions are directly supported by dos32, so
there was no use for the old code; this version supports a
"translation" of some int 10h calls (font & string output).
Intdosx calls are never translated, they just cause a normal
int call. (guess why !)
NOTE: The intdos calls could be in most cases replaced by
assembler instruction templates (which I recommend).
bios functions - the maximum sectors read/write were changed to 16
(a little less for extended sectors)
signal handling - This is the main negative side of this library: only the timer
signal SIGALRM is supported. Signal handling for exceptions
and IRQs would cause too much overhead and for "normal" ints
it is not very useful. But my main reason not to support it
was the fact that, there is nearly always a good workaround
possible or the program can use its own faster methods.
crt0.h - some flag constants concering go32 and DPMI were removed
Many other functions were changed, too, but they should behave excatly the same
like under go32. (If there is no bug.)
V. New functions & API
------------------------
New vars and constants in crt0.h:
extern int _crt0_alloc_mem;
This contains an memory size, the interpretation depends of _crt0_startup_flags.
Default 0 (=if not defined by your program)
extern char _crt0_alloc_dma;
Number of DMA buffers allocated on startup, maximum 8 (Want more ? Hey, there
are only 8 DMA channels !), default 0 (=if not defined by your program)
These flags are the same as under go32:
#define _CRT0_FLAG_PRESERVE_UPPER_CASE 0x0001
#define _CRT0_FLAG_USE_DOS_SLASHES 0x0002
#define _CRT0_FLAG_DROP_EXE_SUFFIX 0x0004
#define _CRT0_FLAG_DROP_DRIVE_SPECIFIER 0x0008
#define _CRT0_FLAG_DISALLOW_RESPONSE_FILES 0x0010
#define _CRT0_FLAG_NO_LFN 0x0400
New flags:
#define _CRT0_FLAG_FILL_MEMORY 0x0020
Fill all alloced memory upon the start. (not bss,only heap,bss is always set to
zero)
#define _CRT0_FLAG_FILL_DEADBEEF 0x0040
If set, fill memory (above) with 0xdeadbeef, else fill with zero.
This is especially useful for debugging uninitialized memory problems. (???)
#define _CRT0_FLAG_NO_EXCEPTION_AT_ALL 0x0800
Don't install any exception handler, just rely on dos32. Same as linking with
noexcept.o .
#define _CRT0_FLAG_NO_EXCEPTION_8 0x1000
Don't install exception handler 8.
#define _CRT0_FLAG_ALLOC_MEM_CONTAINS_MIN 0x2000
Defines how _crt0_alloc_mem is interpreted:
If set it contains the amount memory which is alloced by the program
(WARNING: in this case _crt0_alloc_mem should be > than 32 kB otherwise
the prog will abort/crash)
If not set it contains the amount memory which must remain free. (Default)
#define _CRT0_FLAG_GRAP_ALL_MEM 0x4000
Just graps all mem aviable - only one alloc call is used. I though this useful
to avoid trouble when running the dos32 prog under go32 (p.e. stubify called by
make;no memsize testing is made), but it doesn't solve the problems.
New types of <sys/cltypes.h>:
typedef unsigned short _cl_selector;
A selector.
typedef unsigned short _cl_segment;
A real mode segment.
typedef void * _cl_flatptr;
A flat pm ptr.
typedef struct { unsigned long offset; unsigned short selector; } _cl_farptr;
A protected mode far ptr.
typedef struct {
unsigned long offset;
unsigned long selector;
} _cl_large_farptr;
A protected mode far ptr. (large version, sometimes needed for push/pop)
Vars and functions of dos32api.h:
extern unsigned long __dos32_prog_base;
The base address of the program.
extern unsigned long __exe_length;
The length of the exe file reported by dos32. (Additional data at the end of
the executable isn't included, I think.)
extern _cl_flatptr __psp_address;
Flat address of the programs PSP. (normal DOS PSP, in low memory)
extern _cl_flatptr __env_address;
Flat address of the programs environment. (normal DOS environment, in low memory)
extern _cl_flatptr __dos32_dos_buffer;
Flat address of DOS32 8 Kb transfer buffer in low memory.
extern unsigned short __dos32_version;
Version of DOS32, packed BCD.
extern _cl_selector __dos32_ds;
Programs data selector
extern _cl_selector __dos32_cs;
Programs code selector
extern _cl_selector __dos32_zero;
Zero base selector
extern _cl_segment __dos32_dos_buffer_seg;
DOS real mode segment of DOS32 transfer buffer.
extern unsigned char __dos32_system;
The system DOS32 under which is running.
Can have the following values:
#define DOS32_SYSTEM_RAW_DOS 1
#define DOS32_SYSTEM_XMS 2
#define DOS32_SYSTEM_VCPI 4
#define DOS32_SYSTEM_DPMI 8
extern _cl_flatptr __vga_video_mem;
Flat address of VGA video mem (at A0000).
extern _cl_flatptr __primary_screen_address;
Flat address of primary screen. (at B0000 or B8000)
extern _cl_flatptr __secondary_screen_address;
Flat address of secondary screen. (at B0000 or B8000)
typedef struct {
unsigned long physical; - physical address of DMA buffer
_cl_flatptr logical; - flat address of DMA buffer
} __dma_address_info;
extern __dma_address_info __dos32_prealloced_dma[8];
This array contains the DMA channels allocated on startup.
#define __DOS32_DTA ((char *)__psp_address+0x80)
The DTA is at the standard DTA in the PSP.
typedef struct {
unsigned long edi,esi,ebp,reserved,ebx,edx,ecx,eax;
unsigned short flags,es,ds,fs,gs,ip,cs,sp,ss;
} _dos32_regs;
Register struct for the real mode int and proc calls.
All these functions return !=0 if they fail, 0 on success
extern int __dos32_get_dma_buffer(unsigned long *physical_address,void **block_address);
Allocate a DMA buffer.
extern int __dos32_free_dma_buffer(void);
Free the last allocated DMA buffer. Warning ! This will mess up, if you call any
DOS32 get DMA buffer / memory functions directly.
extern int __dos32_call_realmode_int(unsigned char number,_dos32_regs *regs,char flags);
Call an real mode int.
extern int __dos32_call_realmode_proc_retf(_dos32_regs *regs,char flags);
Call an real mode proc with retf.
extern int __dos32_call_realmode_proc_iret(_dos32_regs *regs,char flags);
Call an real mode proc with iret.
These function can't fail:
extern void __dos32_set_protect_mode_int_vec(char number,_cl_farptr *vector);
Set a protected mode interrupt vector.
extern void __dos32_get_protect_mode_int_vec(char number,_cl_farptr *vector);
Get a protected mode interrupt vector.
int __dos32_get_true_protect_mode_int_vec(char number,_cl_farptr *vector);
Gets the original protected mode interrupt vector. (The vector of the interrupt
that was installed before the startup code set up it's own handlers.)
Returns 1, if the startup code has installed a different handler, otherwise 0.
BEWARE: This is only for chaining down to an original handler, if you want
the actual handler call the function above.
/* these functions return 0 if they fail, otherwise an address */
extern _cl_flatptr __dos32_set_physical_memory_mapping(unsigned long physical,unsigned long size);
Sets a physical memory mapping and returns a flat address pointer to the start.
extern long __dos32_get_iret_call_back(_cl_flatptr address);
Requests an real mode iret call back for a protected mode proc.
Returns an real mode (!) pointer to the call back.
extern long __dos32_get_retf_call_back(_cl_flatptr address);
Requests an real mode retf call back for a protected mode proc.
Returns an real mode (!) pointer to the call back.
Macros for converting real mode adresses to flat.
#define __real2linear(a) ((((a) & 0xffff0000U) >> 12)+((a) & 0xffffU))
A real mode address to linear address.
#define __real2flat(a) (void *)(__real2linear(a)-__dos32_prog_base)
A real mode address to flat protected mode address.
#define __seg2linear(a) ((a)<<4)
A real mode segment to linear address.
#define __seg2flat(a) (void *)(__seg2linear(a)-__dos32_prog_base)
A real mode segment to flat protected mode address.
This is the only function which remains of dpmi.h.
void __dpmi_yield(void);
This is a "release timeslice" call. Does nothing if no DPMI installed -> so
I've included it.
The cbreak modes:
#define DOS32_CBREAK_IGNORE 1 - ignore any <CTRL-BREAK> and <CTRL-C> presses
#define DOS32_CBREAK_COUNT 2 - when ignoring, set an internal flag if
<CTRL-BREAK> is pressed
void __dos32_set_cbreak_mode(char mode);
Set the cbreak mode.
int __dos32_cbreak_hit(void);
Gets the state of the internal cbreak flag and sets it to zero.
long __dos32_load_dll(const char *name,const unsigned long dll_pos,
void **entry_point,void **dll_start);
This function loads a DOS32 dynamic link library.
name - filename of the dll.
dll_pos - start of the dll in the file (this enables adding dlls to the exe
file)
entry_point - a pointer where the entry point of the dll is stored
dll_start - a pointer where the start of the dll in mem is stored, you can
free the dll's memory with a simple free(dll_start).
Returns:
values>0 -> size of dll loaded
values<0 one of the following errors
#define DOS32_DLL_NO_MEM -1 - no free memory for dll
#define DOS32_DLL_FILE_ERROR -2 - error when accessing dll file
#define DOS32_DLL_BAD_DLL -3 - bad dll / file no dll
#define DOS32_DLL_LOAD_ERROR -4 - error during loading of dll
VI. New command line options
-----------------------------
For gcc (only when swap.bat enabled dos32 output via gcc)
-stackXXXXX
Same as -stack for ld, but no whitespace between switch and argument.
-stubXXXXXX
Same as -s for stubify.
For ld.exe (the GNU linker)
-stack XXXXXX
Sets the stacksize of the executable (ignored for dlls). Default 64k
Minimum: 16k (?)
new emulations: i386dos32 , i386dos32dll
new targets: i386-dos32 , i386-dos32-dll
Warning these targets are for output ONLY. Using them as input targets will
cause ld to abort. So, don't set GNUTARGET to one of these.
For stubify.exe:
-c
Compress the executable (only for DOS32).
-l
Show DOS32 logo when running the executable.
-sXXXXX
Uses a certain stubloader (not the default 225 bytes stub). -s without any
filename causes stubify to search dos32.exe on the path.
NOTE: stubify still handles coff output.
For editd32.exe:
To get infos about the switch, run it without any arguments.
This program is used for changing the stubloader or compression of DOS32
executables.
VII. How to compile the sources
-------------------------------
First decompress sources.zip with pkunzip -d in the djgpp base dir.
The library can be directly compiled by changing the directory to SCR\LIBDOS32
and call makeall.bat. All sources should compile without problems if you use the
standard directories. You might want to change the alignment of loops etc. in
gcc.opt - I've set it to 2, because I think larger values it will increase
significantly the size of the library but not its speed. (Most library functions
aren't called soooo often and if you really, really, really want speed at any
price - compile the sources files of the most important function with -S an
optimize the asm code by hand)
To compile the linker you will need the original GNU linker sources. (ld version
2.5.2, bfd version 2.5)
1. Copy the files in SCR\NEWBFD to the bfd directory and the ones in SCR\NEWLD
ld source directory.
2. Run configur.bat in both source directories.
3. Make the liberty library.
4. Run make in the bfd directory.
5. Run make in the ld source directory.
-> You have a brand new ld.exe.
NOTE: Due to the make bug of DOS32 (mentioned later in this documentation)
I strongly recommend that you compile editd32, stubify and ld as go32
executables. (ld won't compile as DOS32 anyway.)
For ld.exe you must "swap" (via swap.bat) back to DOS32 gcc output,
for stubify.exe and editd32.exe you must #-out the EXETARGET = DOS32
line in makefile.inc in SCR\LIBDOS32. (by default #-outed)
VII. Known bugs and problems
----------------------------
1. make bug:
Although most go32-applications run DOS32 files without problems (p.e. gcc),
when invoked by make the DOS32 application (p.e. stubify) fails to allocate
memory for the heap. I'm not sure whether this is a bug in make, DOS32 or
crt0.s - I haven't found any clues about it.
If you found solution -> mail me.
2. DOS32 zero write bug:
DOS32 itself has the bug that zero writes doesn't truncate the file a the
actual position, so the real mode int must be called in this cases.
3. Crash on no memory for DMA:
If there is no free memory and you request a DMA buffer the program crashes.
I dunno if this is caused by DOS32 or the program. I haven't tested this, it
did turn up only one time in crt0.
Other bugs:
If you found an other bug, send me mail. But before you do that, make SURE THAT
IT IS REALLY A BUG IN LIBC.A OR LD.EXE AND NOT IN YOUR PROGRAM.
You can send me the solution to the bug, too. ;)
I can't grantee that the library is 100% bug free. I've tested only a little
and it is nearly impossible to test any situation for library anyway.
I haven't tested if the library works with the c++ iostreams at all.
VIII.Contact the author and get the original GNU stuff
------------------------------------------------------
The author:
FIDO: christian lageman@2:2490/4015.23 (preferred)
EMAIL: cl@matrix.infox.com
These addresses, however, might change in the near future.
You can also try it at:
ECTO TRAXX 49-9504-678
Leave a mail for rasputin or contact the sysop (e605).
If you need the original DJGPP or BINUTILS sources use one the the ftp sites
in info.ftp or call Ecto Traxx and leave a mail to rasputin or the sysop.
IX. Credits & greets
---------------------
Credits
DJ Delorie
CW Sandmann
Adam Seychell
Free Software Fountation
for the rest see the legal stuff section
Greetz
RR
B2B
E605
SANCTION
LD
TRAN
N-FACTOR
CUBIC ^= DOJ
FBK
PURGE
IMPHOBIA
ORANGE
NOOON
BOMB20
AMABLE
SBR
HBE
ENERGETIC
PHAT
ZYKLOP
UE
rest of the world